<?php

namespace App\Api\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LogOutStorageModel extends Model
{
    use HasFactory;
    protected $table = 'log_outstorage';

    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * $dates 数组内的列转换为日期格式
     *
     * @var array
     */
    protected $dates = [
        'out_storage_time',
    ];

    //今日出库总数
    static public function getTodayOutCount($condition, $startTime, $endTime)
    {
        return SELF::where($condition)
            ->where('type', '!=', 1)
            ->whereBetween('created_at', [$startTime, $endTime])
            ->count();
    }

    //今日出库总数
    static public function getTodayAllocateCount($condition, $startTime, $endTime)
    {
        return SELF::where($condition)
            ->where('type', '=', 1)
            ->whereBetween('created_at', [$startTime, $endTime])
            ->count();
    }
}
